/**
 * Created by Administrator on 2017/5/16 0016.
 */
require(["jquery", "echarts", "bbcare", 'migrate_jqprint', 'jqprint', "scprit/department/vm/growthDevelopmentDetailsData.js"], function ($, echarts, $bb, migrate, $print, $tpl) {
    var URL = $bb.baseUrl("department") + "followup/service"
    var obj = $bb.getPageParams()
    var userId = obj.userId
    var growthRecordId = obj.growthRecordId//接收传入的用户growRecordId
    var ageType = "01", scoreType = "01", sex
    growthInit(growthRecordId, ageType, scoreType)
    function trends (dom, res, interval, i, sexColor) {
        var myChart = echarts.init(document.getElementById(dom))
        var colors = ['#12aa59', '#ffb13d', '#e76b7d', '#6d555b']//0--SD0,1--SD1,SD1neg,2--SD2,SD2neg,3--SD3,SD3neg
        var option = {
            textStyle: {
                fontSize: "15px",
                color: "#fff"
            },
            tooltip: {
                trigger: 'item',
                axis: "x",
                formatter: function (params, ticket, callback) {
                    if (res.xType == "height") {
                        var val = ' '
                        if (params.seriesName == "baby") {
                            if (params.data instanceof Array) {
                                val += res.xName.substring(0, 2) + ": " + parseFloat(params.data[0]).toFixed(3) + "<br/>" + res.yName.substring(0, 2) + ": " + parseFloat(params.data[1]).toFixed(3)
                            } else {
                                if (params.componentType == "markPoint") {
                                    val += res.xName.substring(0, 2) + ": " + parseFloat(params.data.coord[0]).toFixed(3) + "<br/>" + res.yName.substring(0, 2) + ": " + parseFloat(params.data.coord[1]).toFixed(3)
                                } else {
                                    val += res.xName.substring(0, 2) + ": " + parseFloat(params.data.value[0]).toFixed(3) + "<br/>" + res.yName.substring(0, 2) + ": " + parseFloat(params.data.value[1]).toFixed(3)
                                }
                            }
                        } else {
                            val += parseFloat(params.data[0]).toFixed(3) + "/" + params.data[1]
                        }
                    }
                    if (res.xType == "age") {
                        val = " "
                        if (params.seriesName == "baby") {
                            var babyAge
                            if (params.data instanceof Array) {
                                babyAge = $tpl.babyAgeDeal(res, parseFloat(params.data[0]))
                                val += res.xName.substring(0, 2) + ": " + babyAge + "<br/>" + res.yName.substring(0, 2) + ": " + parseFloat(params.data[1]).toFixed(3)
                            } else {
                                if (params.componentType == "markPoint") {
                                    babyAge = $tpl.babyAgeDeal(res, parseFloat(params.data.coord[0]))
                                    val += res.xName.substring(0, 2) + ": " + babyAge + "<br/>" + res.yName.substring(0, 2) + ": " + parseFloat(params.data.coord[1]).toFixed(3)
                                } else {
                                    babyAge = $tpl.babyAgeDeal(res, parseFloat(params.data.value[0]))
                                    val += res.xName.substring(0, 2) + ": " + babyAge + "<br/>" + res.yName.substring(0, 2) + ": " + parseFloat(params.data.value[1]).toFixed(3)
                                }
                            }
                        } else {
                            val += params.seriesName + ":" + "&nbsp;&nbsp;" + parseFloat(params.data[1]).toFixed(3)
                        }
                    }
                    return val
                }
            },
            grid: {
                left: '5%',
                right: '10%',
                bottom: '8%',
                top: '10%',
                containLabel: true
            },
            xAxis: {
                type: 'value',
                name: res.xName,
                nameLocation: "middle",
                nameGap: "27",
                scale: true,
                boundaryGap: false,
                splitLine: { lineStyle: { color: "#eee" } }, //分隔线颜色
                splitArea: { show: false },//保留网格区域
                min: res.xMin,
                max: res.xMax,
                interval: interval,
                axisLine: {
                    lineStyle: {
                        color: "#8e7f8a"
                    }
                },
                axisLabel: {
                    textStyle: {
                        color: "#fff"
                    },
                    formatter: function (value, index) {
                        if (res.timeUnit != "年") {
                            if (dom != "h-wRatio") {
                                return value % 2 == 0 ? value : ""
                            } else {
                                return value
                            }
                        } else {
                            return value
                        }
                    }
                },
                axisTick: {
                    show: false,
                    inside: true
                }
            },
            yAxis: {
                type: 'value',
                min: res.yMin,
                max: res.yMax,
                interval: res.interval,
                name: res.yName,
                nameLocation: "middle",
                nameGap: "24",
                splitLine: { lineStyle: { color: "#eee" } }, //分隔线颜色
                splitArea: {
                    show: true,//保留网格区域
                    areaStyle: {
                        color: "#fff"
                    }
                },
                axisLine: {
                    lineStyle: {
                        color: "#8e7f8a"
                    }
                },
                axisLabel: {
                    textStyle: {
                        color: "#fff"
                    }
                },
                axisTick: {
                    show: false
                }
            },
            series: [
                {
                    name: res.sd3.name,
                    type: 'line',
                    smooth: "true",
                    symbol: 'circle',
                    hoverAnimation: false,
                    data: res.sd3.sd3,
                    itemStyle: {
                        normal: {
                            color: "transparent",
                            lineStyle: {
                                color: colors[res.sd3.num],
                                width: 0.5
                            }
                        }
                    }
                },
                {
                    name: res.sd2.name,
                    type: 'line',
                    smooth: "true",
                    symbol: 'circle',
                    hoverAnimation: false,
                    data: res.sd2.sd2,
                    itemStyle: {
                        normal: {
                            color: "transparent",
                            lineStyle: {
                                color: colors[res.sd2.num],
                                width: 0.5
                            }
                        }
                    }
                },
                {
                    name: res.sd1.name,
                    type: 'line',
                    smooth: "true",
                    symbol: 'circle',
                    hoverAnimation: false,
                    data: res.sd1.sd1,
                    itemStyle: {
                        normal: {
                            color: "transparent",
                            lineStyle: {
                                color: colors[res.sd1.num],
                                width: 0.5
                            }
                        }
                    }
                },
                {
                    name: res.sd0.name,
                    type: 'line',
                    smooth: "true",
                    symbol: 'circle',
                    hoverAnimation: false,
                    data: res.sd0.sd0,
                    itemStyle: {
                        normal: {
                            color: "transparent",
                            lineStyle: {
                                color: colors[res.sd0.num],
                                width: 0.5
                            }
                        }
                    }
                },
                {
                    name: res.sd1neg.name,
                    type: 'line',
                    smooth: "true",
                    symbol: 'circle',
                    hoverAnimation: false,
                    data: res.sd1neg.sd1neg,
                    itemStyle: {
                        normal: {
                            color: "transparent",
                            lineStyle: {
                                color: colors[res.sd1neg.num],
                                width: 0.5
                            }
                        }
                    }
                },
                {
                    name: res.sd2neg.name,
                    type: 'line',
                    smooth: "true",
                    symbol: 'circle',
                    hoverAnimation: false,
                    data: res.sd2neg.sd2neg,
                    itemStyle: {
                        normal: {
                            color: "transparent",
                            lineStyle: {
                                color: colors[res.sd2neg.num],
                                width: 0.5
                            }
                        }
                    }
                },
                {
                    name: res.sd3neg.name,
                    type: 'line',
                    smooth: "true",
                    symbol: 'circle',
                    hoverAnimation: false,
                    data: res.sd3neg.sd3neg,
                    itemStyle: {
                        normal: {
                            color: "transparent",
                            lineStyle: {
                                color: colors[res.sd3neg.num],
                                width: 0.5
                            }
                        }
                    }
                },
                {
                    name: 'baby',
                    type: 'line',
                    data: res.grownRecord,
                    symbol: 'circle',
                    symbolSize: '6',
                    markPoint: {
                        itemStyle: {
                            normal: {
                                color: res.grownNowRecord[2]
                            }
                        },
                        data: [
                            {
                                xAxis: res.grownNowRecord[0],
                                yAxis: res.grownNowRecord[1]
                            }
                        ]
                    },
                    itemStyle: {
                        normal: {
                            color: sexColor,
                            lineStyle: {
                                width: 3
                            }
                        },
                        emphasis: {
                            color: sexColor
                        }
                    }
                }
            ],
            animation: false
        }
        myChart.setOption(option)
        $(".bg" + i).html('<img src="' + myChart.getDataURL({ type: "png", backgroundColor: '#aaa' }) + '" style="width: 100%;height:100%; "/>')
    }

    function fentonTrends (dom, series, gender) {
        var myChart = echarts.init(document.getElementById(dom))
        // 指定图表的配置项和数据
        var option = {
            title: {
                text: 'Fenton早产儿发育图-' + gender,
                left: "89%",
                top: "1.5%",
                textAlign: 'right',
                textBaseline: "top",
                textStyle: {
                    color: '#fff',
                    fontSize: '12',
                    fontWeight: "normal"
                }
            },
            tooltip: {
                formatter: function (params, ticket, callback) {
                    var val = ""
                    if (params.data instanceof Array) {
                        val += params.seriesName + ": " + parseFloat(params.data[1]).toFixed(3)
                    } else {
                        if (params.seriesName == "身长" || params.seriesName == "体重" || params.seriesName == "头围") {
                            if (params.componentType != "markPoint") {
                                if (params.seriesName == "体重") {
                                    val += "胎龄:" + $tpl.toPregnancyDay(params.data.value[0]) + "<br/>" + params.seriesName + ":" + parseFloat(params.data.value[1]).toFixed(2)
                                } else {
                                    val += "胎龄:" + $tpl.toPregnancyDay(params.data.value[0]) + "<br/>" + params.seriesName + ":" + parseFloat(params.data.value[1]).toFixed(1)
                                }
                            }
                        } else {
                            val += params.seriesName + ": " + parseFloat(params.data.value[1]).toFixed(3)
                        }
                    }
                    return val
                }
            },
            grid: {
                show: true,
                left: '0',
                right: '0',
                bottom: '3%',
                top: '4%',
                containLabel: true
            },
            xAxis: {
                type: "value",
                name: '胎龄（周）',
                nameLocation: 'middle',
                nameGap: "27",
                nameTextStyle: { color: "#fff" },
                max: 50,
                min: 22,
                interval: 1,
                splitLine: {
                    lineStyle: {
                        color: ["#333", "#ccc", "#333", "#ccc", "#ccc", "#ccc", "#333", "#ccc", "#ccc", "#ccc", "#333", "#ccc", "#ccc",
                            "#ccc", "#333", "#ccc", "#ccc", "#ccc", "#333", "#ccc", "#ccc", "#ccc", "#333", "#ccc", "#ccc", "#ccc"],
                        width: 1
                    }
                },
                axisTick: {
                    show: true,
                    inside: true
                },
                axisLabel: {
                    textStyle: {
                        color: function (value) {
                            return value % 2 != 0 ? "transparent" : "#fff"
                        }
                    }
                }
            },
            yAxis: [
                {
                    name: '体重（kg)                                                             厘米',
                    nameLocation: 'middle',
                    nameGap: "30",
                    nameTextStyle: { color: "#fff" },
                    max: 9,
                    min: 0,
                    interval: 0.1,
                    type: 'value',
                    splitArea: {
                        show: true,//保留网格区域
                        areaStyle: {
                            color: "#fff"
                        }
                    },
                    axisTick: {
                        inside: true
                    },
                    axisLabel: {
                        textStyle: {
                            color: function (value, index) {
                                return value > 4 ? "transparent" : value * 10 % 5 != 0 ? "transparent" : "#fff"
                            }
                        }
                    }
                },
                {
                    name: '体重（kg)                                                                                                         厘米',
                    nameLocation: 'middle',
                    nameGap: "27",
                    nameTextStyle: { color: "#fff" },
                    type: 'value',
                    max: 60,
                    min: -30,
                    interval: 1,
                    axisTick: {
                        inside: true
                    },
                    axisLabel: {
                        textStyle: {
                            color: function (value, index) {
                                return value < 40 ? "transparent" : value % 5 != 0 ? "transparent" : "#FFF"
                            }
                        }
                    }
                },
                {
                    position: 'left',
                    type: 'value',
                    max: 60,
                    min: -30,
                    interval: 1,
                    axisTick: {
                        inside: true
                    },
                    axisLabel: {
                        textStyle: {
                            color: function (value, index) {
                                return value < 15 ? "transparent" : value % 5 != 0 ? "transparent" : "#FFF"
                            }
                        }
                    }
                },
                {
                    type: 'value',
                    position: 'right',
                    max: 9,
                    min: 0,
                    interval: 0.1,
                    splitLine: {
                        lineStyle: {
                            color: ["#333", "#ccc", "#ccc", "#ccc", "#ccc"],
                            width: 1
                        }
                    },
                    axisTick: {
                        inside: true
                    },
                    axisLabel: {
                        textStyle: {
                            color: function (value, index) {
                                return value > 6.5 ? "transparent" : value * 10 % 5 != 0 ? "transparent" : "#FFF"
                            }
                        }
                    }
                }
            ],
            animation: false,
            series: series
        }
        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option)
        $(".fetonBg").html('<img src="' + myChart.getDataURL({ type: "png", backgroundColor: '#aaa' }) + '" style="width: 100%;height:100%;"/>')
    }
    //曲线列表：00001:体重，00002:身长，00003:头围，00004:身长别体重 00005:(BMI)年龄别体重
    function trendsInit (growthRecordId, userId, ageType, scoreType, sexColor) {
        $bb.ajax({
            url: URL + "/patient/growth/getGrowthCurvedata",
            data: JSON.stringify({
                data: {
                    "growthRecordId": growthRecordId,
                    "userId": userId,
                    "ageType": ageType,
                    "scoreType": scoreType
                }
            }),
            success: function (data) {
                if (data.success) {
                    var gender
                    var scoreType = data.data.scoreType
                    if (sexColor == "#0596d5") {
                        gender = "男"
                    } else {
                        gender = "女"
                    }
                    if (data.data.curveType == "01") {
                        if (data.data.curvadataList[0].type == '00001') {
                            var data0 = data.data.curvadataList[0]
                            var standard0 = data0.curvedata
                            standard0.type = "weight"
                            standard0.sex = gender
                            standard0.scoreType = scoreType
                            var res0 = $tpl.dataDo2(standard0)
                            res0.yName = "体重（kg)"
                            res0.xType = "age"
                            trends("weight", res0, 1, 1, sexColor)
                        }
                        if (data.data.curvadataList[1].type == '00002') {
                            var data1 = data.data.curvadataList[1]
                            var standard1 = data1.curvedata
                            standard1.type = "height"
                            standard1.sex = gender
                            standard1.scoreType = scoreType
                            var res1 = $tpl.dataDo2(standard1)
                            if (res1.timeUnit == "年") {
                                res1.yName = "身高（cm)"
                                $(".heightName").html("身高")
                            } else {
                                res1.yName = "身长（cm)"
                                $(".heightName").html("身长")
                            }
                            res1.xType = "age"
                            trends("height", res1, 1, 2, sexColor)
                        }
                        if (data.data.curvadataList[2].type == '00003') {
                            var data2 = data.data.curvadataList[2]
                            var standard2 = data2.curvedata
                            standard2.type = "head"
                            standard2.sex = gender
                            standard2.scoreType = scoreType
                            var res2 = $tpl.dataDo2(standard2)
                            res2.xType = "age"
                            res2.yName = "头围（cm)"
                            trends("head", res2, 1, 3, sexColor)
                        }
                        if (data.data.curvadataList[3].type == '00004') {
                            //0-2岁，身长别体重
                            $(".length-weight-age").html("身长别体重发育曲线")
                            var data3 = data.data.curvadataList[3]
                            var standard3 = data3.curvedata
                            standard3.type = "wl"
                            standard3.sex = gender
                            standard3.scoreType = scoreType
                            var res3 = $tpl.dataDo2(standard3)
                            res3.xName = "身长（cm)"
                            res3.xType = "height"
                            res3.yName = "体重（kg)"
                            trends("h-wRatio", res3, 5, 4, sexColor)
                        } else if (data.data.curvadataList[3].type == '00005') {
                            //2-5岁，BMI，年龄别体重
                            $(".length-weight-age").html("BMI曲线")
                            var data4 = data.data.curvadataList[3]
                            var standard4 = data4.curvedata
                            standard4.type = "wl"
                            standard4.sex = gender
                            standard4.scoreType = scoreType
                            var res4 = $tpl.dataDo2(standard4)
                            res4.xName = "年龄（岁)"
                            res4.xType = "age"
                            res4.yName = "BMI（kg/㎡)"
                            trends("h-wRatio", res4, 1, 4, sexColor)
                        }
                    } else {
                        if (data.data.curvadataList[0].timeUnit == "年") {
                            $(".heightName").html("身高")
                        } else {
                            $(".heightName").html("身长")
                        }
                        var series = $tpl.fentonDeal(data, sexColor, gender)
                        fentonTrends("feton", series, gender)
                    }
                }
            }
        })
    }
    /**
     * 请求修改随访建议的接口
     */
    var ajaxModifyGuides = function (guides, remark, guideTips) {
        $bb.ajax({
            url: URL + "/patient/evaluation/guidemodify",
            data: JSON.stringify({
                data: {
                    "examinationPaperName": "GROWTH",
                    "userId": userId,
                    "evaluationId": growthRecordId,
                    "guide": guides,
                    "remark": remark
                }
            }),
            success: function (data) {
                ajaxGetGuides(guideTips)
            }
        })
    }
    var onModifyGuides = function () {
        var guideTips = $(this).data("guideTips")
        if ($(this).attr("type") == "modify") {
            if ($("#tips").html() == "暂无指导建议") {
                $("#tips").html("")
            }
            $("#tips").attr("contentEditable", true).addClass("edit")
            $(this).attr("type", "save").html('<i class="fa fa-check-square" aria-hidden="true"></i>&nbsp;确认修改')
        } else if ($(this).attr("type") == "save") {
            $("#tips").removeAttr("contentEditable").removeClass("edit")
            $(this).attr("type", "modify").html('<i class="fa fa-pencil-square-o" aria-hidden="true"></i>&nbsp;修改建议')
            var guides = $.trim($("#tips").html())
            var remark = $.trim($("#remark").html())
            if (!guides) {
                $("#guides").html("暂无指导建议")
                guides = "暂无指导建议"
            }
            ajaxModifyGuides(guides, remark, guideTips)
        }
    }
    var onModifyRemark = function () {
        var guideTips = $(this).data("guideTips")
        if ($(this).attr("type") == "modify") {
            $("#remark").attr("contentEditable", true).addClass("edit")
            if ($("#remark").html() == "暂无备注") {
                $("#remark").html("")
            }
            $(this).attr("type", "save").html('<i class="fa fa-check-square" aria-hidden="true"></i>确认修改')
        } else if ($(this).attr("type") == "save") {
            $("#remark").removeAttr("contentEditable").removeClass("edit")
            $(this).attr("type", "modify").html('<i class="fa fa-pencil-square-o" aria-hidden="true"></i>修改备注')
            var remark = $.trim($("#remark").html())
            var guides = $.trim($("#tips").html())
            if (!remark) {
                $("#remark").html("暂无备注")
                remark = "暂无备注"
            }
            ajaxModifyGuides(guides, remark, guideTips)
        }
    }
    /**
     * 请求随访建议
     */
    var ajaxGetGuides = function (guideTips) {
        $bb.ajax({
            url: URL + "/patient/evaluation/getGuide",
            data: JSON.stringify({
                data: {
                    "evaluationId": growthRecordId,
                    "examinationPaperName": "GROWTH",
                    "userId": userId
                }
            }),
            success: function (data) {
                var remarkText = "暂无备注"
                if (data.data && data.data.remark) {
                    var remarkText = data.data.remark
                }
                if (data.data && data.data.guide) {
                    var guideText = data.data.guide
                } else {
                    var guideText = ""
                    for (var i = 0; i < guideTips.length; i++) {
                        guideText += guideTips[i].note
                    }
                }
                guideText = guideText == "" ? "暂无指导建议" : guideText
                if (window.__config__.role.indexOf('ReadOnly') > -1) {
                    $('#modifyGuides').css({
                        display: 'none'
                    })
                    $('#modifyRemark').css({
                        display: 'none'
                    })
                }
                $("#tips").html(guideText)
                $("#remark").html(remarkText)
                $("#printTips").html(guideText)
                $("#modifyGuides").unbind("click")
                $("#modifyGuides").data({ "guideTips": guideTips })

                $("#modifyGuides").click(onModifyGuides)
                $("#modifyRemark").unbind("click")
                $("#modifyRemark").data({ "guideTips": guideTips })
                $("#modifyRemark").click(onModifyRemark)
            }
        })
    }
    //获取用户生长发育监测数据基本信息：
    function growthInit (growthRecordId, ageType, scoreType) {
        $tpl.loadingInit({ "id": "#main" })
        $bb.ajax({
            url: URL + "/patient/growth/getGrowthInfo",
            data: JSON.stringify({
                data: {
                    "growthRecordId": growthRecordId,
                    'ageType': ageType,
                    'scoreType': scoreType
                }
            }),
            success: function (data) {
                if (data.success) {
                    var data = data.data
                    var birthDay = data.birthday
                    var pregnanceDay = data.pregnancyDay
                    var hosDepart = data.hospName + "-" + data.departmentName
                    $(".guiderTime").html(data.createTime)
                    $(".guiderDoctor").html(data.doctorName + "(" + hosDepart + ")")
                    var dataRes = $tpl.userInfoDeal(data)
                    $tpl.userInfoInit({ "id": "#main", "value": dataRes })
                    $tpl.printUserInfoInit({ "id": "#printRes", "value": dataRes })
                    $tpl.trendsBoxInit({ "id": "#printImage", "value": dataRes })
                    var oLis = $(".infoList>li").length / 2
                    $(".infoList>li").css("width", 100 / oLis + "%")
                    var ulWidth = $("#tabToggle>ul").width()
                    $("#tabToggle>ul").css("margin-left", "-" + ulWidth / 2 + "px").addClass("pos")
                    sex = data.gender
                    if (sex == "F") {
                        $(".panel").addClass("bgG")
                        $(".panel-heading").addClass("girlsBg")
                        $(".outfit").addClass("girls")
                        $("#tabToggle").on("click", "div", function () {
                            $(this).addClass("girlsTabChecked").siblings().removeClass('girlsTabChecked')
                            var parentType = $(this).parents("li").attr("type")
                            var ageType, scoreType
                            if (parentType == "age") {
                                ageType = $(this).attr("ageType")
                                scoreType = $("#tabToggle>ul>li").eq(1).find("div.girlsTabChecked").attr("curveType")
                            } else {
                                scoreType = $(this).attr("curveType")
                                ageType = $("#tabToggle>ul>li").eq(0).find("div.girlsTabChecked").attr("ageType")
                            }
                            growthInit(growthRecordId, ageType, scoreType)
                        })
                        trendsInit(growthRecordId, userId, ageType, scoreType, "#e47db2")
                    } else {
                        $(".panel").addClass("bgB")
                        $(".panel-heading").addClass("boyBg")
                        $(".outfit").addClass("boys")
                        $("#tabToggle").on("click", "div", function () {
                            $(this).addClass("boysTabChecked").siblings().removeClass('boysTabChecked')
                            var parentType = $(this).parents("li").attr("type")
                            var ageType, scoreType
                            if (parentType == "age") {
                                ageType = $(this).attr("ageType")
                                scoreType = $("#tabToggle>ul>li").eq(1).find("div.boysTabChecked").attr("curveType")
                            } else {
                                scoreType = $(this).attr("curveType")
                                ageType = $("#tabToggle>ul>li").eq(0).find("div.boysTabChecked").attr("ageType")
                            }
                            growthInit(growthRecordId, ageType, scoreType)
                        })
                        trendsInit(growthRecordId, userId, ageType, scoreType, "#0596d5")
                    }
                    //历史记录列表加载：
                    getHostoryList(growthRecordId, pregnanceDay, birthDay, userId)
                    //医生建议：
                    sex == "F" ? $(".babyInfo .tips").addClass("c-red") : $(".babyInfo .tips").addClass("c-blue")
                    ajaxGetGuides(data.guideDetails)
                }
            }
        })
    }

    var _once = true
    var getHostoryList = function (growthRecordId, pregnanceDay, birthDay, userId, callback) {
        $bb.ajax({
            url: URL + "/patient/growth/history",
            data: JSON.stringify({
                data: {
                    "page": 1,
                    "rows": 150,
                    "userId": userId
                }
            }),
            success: function (data) {
                if (data.rows.length === 0) { $bb.openPage('growingDevelopment') }
                if (data.success) {
                    var resData = $tpl.testTime(birthDay, pregnanceDay, data.rows)
                    $tpl.historyListInit({ "id": "#growingHistory", "data": resData })
                    $("#growingHistory").find("li").each(function (i) {
                        var $this = $(this)
                        if ($this.attr("growthRecordId") == growthRecordId) {
                            if (sex == "F") {
                                $this.addClass("checkG").siblings().removeClass("checkB")
                            } else {
                                $this.addClass("checkB").siblings().removeClass("checkG")
                            }
                        }
                    })
                    callback && callback()
                    if (_once) {
                        if (!$($('#growingHistory li').first()).attr('class')) {
                            $('#growingHistory li').first().click()
                        }
                        _once = !_once
                    }
                    if (window.__config__.role.indexOf('ReadOnly') > -1) {
                        $('span.delete').css({
                            display: 'none'
                        })
                    }
                    // 添加删除功能
                    $('span.delete').click(function (e) {
                        var id = $(this).data('id')
                        var url = $bb.baseUrl('followup')
                        $bb.toastConfirmShow(function () {
                            $bb.ajax({
                                url: url + 'followup/service/patient/growth/delGrowthRecord',
                                data: JSON.stringify({
                                    data: {
                                        recordId: id
                                    }
                                }),
                                success: function (res) {
                                    var parentType = $(this).parents("li").attr("type")
                                    var ageType, scoreType
                                    if (parentType == "age") {
                                        ageType = $(this).attr("ageType")
                                        scoreType = $("#tabToggle>ul>li").eq(1).find("div.girlsTabChecked").attr("curveType")
                                    } else {
                                        scoreType = $(this).attr("curveType")
                                        ageType = $("#tabToggle>ul>li").eq(0).find("div.girlsTabChecked").attr("ageType")
                                    }
                                    getHostoryList(growthRecordId, pregnanceDay, birthDay, userId, function () {
                                        _once = true
                                    })
                                }
                            })
                        }, '', "确定删除此条记录吗1")
                        e.stopPropagation()
                    })
                }
            }
        })
    }

    $("#growingHistory").on("click", "li", function () {
        if (sex == "F") {
            $(this).addClass("checkG").siblings().removeClass("checkG")
        } else {
            $(this).addClass("checkB").siblings().removeClass("checkB")
        }
        var growthRecordId = $(this).attr("growthRecordId")
        growthInit(growthRecordId, ageType, scoreType)
    })
    var printReport = function () {
        var params = $(this).data("params")
        var $pc = $(params.dom)
        $pc.jqprint({
            debug: false, //如果是true则可以显示iframe查看效果（iframe默认高和宽都很小，可以再源码中调大），默认是false
            importCSS: true, //true表示引进原来的页面的css，默认是true。（如果是true，先会找$("link[media=print]")，若没有会去找$("link")中的css文件）
            printContainer: true, //表示如果原来选择的对象必须被纳入打印（注意：设置为false可能会打破你的CSS规则）。
            operaSupport: true//表示如果插件也必须支持歌opera浏览器，在这种情况下，它提供了建立一个临时的打印选项卡。默认是true
        })
        return
    }
    var topbars = [
        {
            "icon": "fa fa-print",
            "name": "打印报告",
            "callback": printReport,
            "params": { "dom": "#printContent" }
        }
    ]
    $bb.toolbar(topbars)
    $(window).resize(function () {
        var width = $(".bg").width()
        $(".bg>div").css({ "width": width })
        $(".bg>div>canvas").css({ "width": width })
    })
})